//
//  CGContextObject.h
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/9/1.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import "CGContextObjectConfig.h"
#import "GradientColor.h"
@class CGContextObject;
typedef void(^CGContextObjectDrawBlock_t)(CGContextObject *contextObject);

@interface CGContextObject : NSObject


@property (nonatomic,readonly) CGContextRef context;

//初始化
- (instancetype)initWithCGContext:(CGContextRef )context config:(CGContextObjectConfig  *)config;
//使用contextConfig,设置context
- (void)useCGContextConfig:(CGContextObjectConfig *)contextConfig storeAsCurrentConfig:(BOOL)asCurrentConfig;

#pragma mark -- 画线

- (void)beginPath;
//封闭当前线路
- (void)closePath;
//开始绘制图片
- (void)strokePath;
//使用非零绕数规则填充当前路径
- (void)fillPath;
//填充
- (void)drawPathWithDrawingMode:(CGPathDrawingMode)drawingMode;
//画一个方框
- (void)addRectPath:(CGRect)rect;
//画一个椭圆
- (void)addEllipseInRectPath:(CGRect)rect;
//画圆弧
- (void)addArcWithCenterPoint:(CGPoint)point radius:(CGFloat)radius
                   startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle
                    clockwise:(BOOL)clockwise;

//根据配置Config画
- (void)contextConfig:(CGContextObjectConfig *)config drawStrokeBlock:(CGContextObjectDrawBlock_t)block;
- (void)contextConfig:(CGContextObjectConfig *)config drawFillBlock:(CGContextObjectDrawBlock_t)block;
- (void)contextConfig:(CGContextObjectConfig *)config drawingMode:(CGPathDrawingMode)drawingMode drawBlock:(CGContextObjectDrawBlock_t)block;

#pragma mark --- 添加点

//移动到某个点
- (void)moveToStartPoint:(CGPoint)point;
//从当前点到某个点画一条直线
- (void)addLineToPoint:(CGPoint)point;
//按照给定的点的数组，画直线。
- (void)addLinePoints:(NSArray <NSValue *> *)points;
//贝塞尔曲线，从当前位置，到终点，有两个基准点
- (void)addCurveToPoint:(CGPoint)point firstControlPoint:(CGPoint)firstControlPoint secondControlPoint:(CGPoint)secondControlPoint;
//贝塞尔曲线，二元曲线，当前位置，到终点，一个基准点
- (void)addQuadCurveToPoint:(CGPoint)point controlPoint:(CGPoint)controlPoint;

#pragma mark - UIGraphicsBeginImageContext 绘制image.

//从这个点做左上角，开始绘制图片
- (void)drawImage:(UIImage *)image atPoint:(CGPoint)point;

- (void)drawImage:(UIImage *)image atPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;

- (void)drawImage:(UIImage *)image inRect:(CGRect)rect;

- (void)drawImage:(UIImage *)image inRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;

- (void)drawImage:(UIImage *)image asPatternInRect:(CGRect)rect;

#pragma mark - State related.
//CGContextSaveGState函数的作用是将当前图形状态推入堆栈。之后，您对图形状态所做的修改会影响随后的描画操作，但不影响存储在堆栈中的拷贝。在修改完成后，您可以通过CGContextRestoreGState函数把堆栈顶部的状态弹出，返回到之前的图形状态。这种推入和弹出的方式是回到之前图形状态的快速方法，避免逐个撤消所有的状态修改；这也是将某些状态（比如裁剪路径）恢复到原有设置的唯一方式。
- (void)saveGState;


- (void)restoreGState;


- (void)drawInCurrentSpecialState:(CGContextObjectDrawBlock_t)block;

#pragma mark - 绘制string.


- (void)drawString:(NSString *)string atPoint:(CGPoint)point withAttributes:(NSDictionary *)attributes;

- (void)drawString:(NSString *)string inRect:(CGRect)rect withAttributes:(NSDictionary *)attributes;

- (void)drawAttributedString:(NSAttributedString *)string atPoint:(CGPoint)point;


- (void)drawAttributedString:(NSAttributedString *)string inRect:(CGRect)rect;

#pragma mark - 绘制gradientColor.

- (void)drawLinearGradientAtClipToRect:(CGRect)rect gradientColor:(GradientColor *)gradientColor startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;





@end
